<%@ page language="java"  import="cn.ac.iscas.bean.project.DocumentType,cn.ac.iscas.bean.project.Project,cn.ac.iscas.bean.project.ProjectDocument" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
    <title>修改项目</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link rel="stylesheet" href="../css/vip.css" type="text/css">
	<SCRIPT language=JavaScript src="../js/jquery.js"></SCRIPT>
    <script language=JavaScript src="../js/FoshanRen.js"></script>
    <script language="javascript" type="text/javascript" src="../js/My97DatePicker/WdatePicker.js">
    <script type="text/javascript" src="../js/showNewDiv.js"></script>
    <link rel="stylesheet" type="text/css" href="../js/extjs/resources/css/ext-all.css"/>
   <script type="text/javascript" charset="utf-8" src="../js/extjs/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/extjs/ext-all.js"></script>
    <script language="javascript">
    function deleteItem(id){
	 if(confirm("你确定要删除")){
	    $.get("projectManage_deleteDocument.action?document.id="+id,
	    function(data){
	    $("#"+id).remove();
	    alert(data);
	    });
      }
    }
   function addApplyingComponent()
   {   
        var tr = document.createElement('tr');
        tr.setAttribute("bgcolor", "f5f5f5");
        var td1 = document.createElement('td');
        td1.setAttribute("width", "25%");
        var td2 = document.createElement('td');
        td2.setAttribute("width", "75%");
       
        var uploadHTML = document.createElement('input');
        uploadHTML.setAttribute("type","file");
        uploadHTML.setAttribute("name","applyingDocument");
        var last = document.getElementById("last");
        var tables = last.parentNode;
        
        tr.appendChild(td1);
        td2.appendChild(uploadHTML);
        tr.appendChild(td2);
        tables.insertBefore(tr,last);
        var button = document.createElement("input");
        button.type = "button";
	    button.value = " 删 除 ";	    
	    td2.appendChild(button);
        button.onclick = function()
	    {
		tables.removeChild(tr);
	   }
    }
    function addOngoingComponent()
   {   
        var tr = document.createElement('tr');
        tr.setAttribute("bgcolor", "f5f5f5");
        var td1 = document.createElement('td');
        td1.setAttribute("width", "25%");
        var td2 = document.createElement('td');
        td2.setAttribute("width", "75%");
       
        var uploadHTML = document.createElement('input');
        uploadHTML.setAttribute("type","file");
        uploadHTML.setAttribute("name","ongoingDocument");
        var ongoing = document.getElementById("ongoing");
        var tables = ongoing.parentNode;
        
        tr.appendChild(td1);
        td2.appendChild(uploadHTML);
        tr.appendChild(td2);
        tables.insertBefore(tr,ongoing);
        var button = document.createElement("input");
        button.type = "button";
	    button.value = " 删 除 "
	    td2.appendChild(button);
        button.onclick = function()
	    {
		tables.removeChild(tr);
	   }
    }
    function addFinishedComponent()
   {   
        var tr = document.createElement('tr');
        tr.setAttribute("bgcolor", "f5f5f5");
        var td1 = document.createElement('td');
        td1.setAttribute("width", "25%");
        var td2 = document.createElement('td');
        td2.setAttribute("width", "75%");
       
        var uploadHTML = document.createElement('input');
        uploadHTML.setAttribute("type","file");
        uploadHTML.setAttribute("name","finishedDocument");
        var finished = document.getElementById("finished");
        var tables = finished.parentNode;
        
        tr.appendChild(td1);
        td2.appendChild(uploadHTML);
        tr.appendChild(td2);
        tables.insertBefore(tr,finished);
        var button = document.createElement("input");
        button.type = "button";
	    button.value = " 删 除 ";	   
	    td2.appendChild(button);
        button.onclick = function()
	    {
		tables.removeChild(tr);
	   }
    }
    function len(s){//获取字符串的字节长度
  return s.length+(s.match(/[^\x00-\xff]/g) ||"").length;//加上匹配到的全角字符长度
}
 
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g,"");
} 
function check(){
var reg=/^\d+$/;//判断是正整数的正则表达式
var LEN20=20,LEN400=400,LEN100=100,LEN1000=1000;
var f,projectNo,projectName,source,reposiblePerson,personInCharge,startTime,endTime,introduction,paperTarget,softwareCopyRightTarget,patentTarget,otherTargets,qualification,note;
projectNo=document.getElementById("projectNo").value;
if(projectNo.trim()==""){
  alert("项目编号不可为空！");
  return false;
}
projectName=document.getElementById("projectName").value;
if(projectName.trim()==""){
  alert("项目名称不可为空！");
  return false;
}
introduction=document.getElementById("introduction").value;
 if(len(introduction)>LEN1000){
  alert("项目简介长度超过"+LEN1000+"字节！");
  return false;
}
paperTarget=document.getElementById("paperTarget").value;
if(paperTarget.trim() !="" && !reg.test(paperTarget)){
  alert("论文指标不是非负整数！");
  return false;
}  

softwareCopyRightTarget=document.getElementById("softwareCopyRightTarget").value;
  if(softwareCopyRightTarget.trim()!=""&&!reg.test(softwareCopyRightTarget)){
  alert("软著指标不是非负整数！");
  return false;
}  
patentTarget=document.getElementById("patentTarget").value;
  if(patentTarget.trim()!=""&&!reg.test(patentTarget)){
  alert("专利指标不是非负整数！");
  return false;
}  
qualification=document.getElementById("qualification").value;

  if(len(qualification)>LEN1000){
  alert("技术指标详细描述长度超过"+LEN1000+"字节！");
  return false;
}

note=document.getElementById("note").value;
  if(len(note)>LEN100){
  alert("备注长度超过"+LEN100+"字节！");
  return false;
}
f=document.getElementById("myform");
f.submit();
}
</script> 
   <s:head theme="xhtml"/>
   <sx:head parseContent="true"/>
</head> 
  <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  <s:form id="myform" action="projectManage_update" namespace="/admin" enctype="multipart/form-data"  method="post">
  <s:hidden name="project.id" value="%{project.id}"/>
  <table id="tables" width="98%" border="0" cellspacing="1" cellpadding="3" align="center">
    <tr bgcolor="6f8ac4"> 
      <td colspan="2" ><font color="#FFFFFF">项目课题信息修改 ：</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目编号  ：</div></td>
      <td width="75%"><s:textfield name="project.projectNo" id="projectNo" value="%{project.projectNo}" maxlength="20" /><font color="#FF0000">*</font></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目名称  ：</div></td>
      <td width="75%"><s:textfield name="project.projectName" id="projectName" value="%{project.projectName}" size="70" maxlength="400"/><font color="#FF0000">*</font></td>
    </tr>
     <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目来源 ：</div></td>
      <td width="75%"><s:textfield name="project.source" value="%{project.source}" maxlength="100"/></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目责任人：</div></td>
      <td width="75%"><s:textfield name="project.reposiblePerson" value="%{project.reposiblePerson}" maxlength="20"/></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目负责人 ：</div></td>
      <td width="75%"><s:textfield name="project.personInCharge" value="%{project.personInCharge}" maxlength="20"/></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目开始时间 ：</div></td>
      <td width="75%"><input type="text" name="project.startTime" class="Wdate" onfocus="WdatePicker()" value="<s:date name="project.startTime" nice="false" format="yyyy-MM-dd"/>"/> </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目结束时间 ：</div></td>
      <td width="75%"><input type="text" name="project.endTime" class="Wdate" onfocus="WdatePicker()" value="<s:date name="project.startTime" nice="false" format="yyyy-MM-dd"/>"/> </td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%" valign="top"> <div align="right">项目简介 ：</div></td>
      <td width="75%"><s:textarea name="project.introduction" id="introduction" cols="60" rows="10" value="%{project.introduction}"></s:textarea></td>
	</tr>
	<tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">论文指标 ：</div></td>
      <td width="75%"> <s:textfield name="project.paperTarget" id="paperTarget" maxlength="10" value="%{project.paperTarget}" ></s:textfield></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">软著指标 ：</div></td>
      <td width="75%"> <s:textfield name="project.softwareCopyRightTarget" id="softwareCopyRightTarget" maxlength="10" value="%{project.softwareCopyRightTarget}"></s:textfield></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">专利指标 ：</div></td>
      <td width="75%"> <s:textfield name="project.patentTarget" id="patentTarget" maxlength="10" value="%{project.patentTarget}"></s:textfield></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">其他指标 ：</div></td>
      <td width="75%"><s:textfield name="project.otherTargets" value="%{project.otherTargets}" maxlength="100"/></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">技术指标详细描述 ：</div></td>
      <td width="75%"><s:textarea name="project.qualification" id="qualification" cols="60" rows="8" value="%{project.qualification}"/></td>
    </tr>
    <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">项目状态 ：</div></td>
      <td width="75%"><s:radio name="project.state" list="#{'申请中':'申请中','进行中':'进行中','已结题':'已结题'}" value="%{project.state}"/></td>
    </tr>
     <tr bgcolor="f5f5f5"> 
      <td width="25%" valign="top"> <div align="right">备注 ：</div></td>
      <td width="75%"><s:textarea name="project.note" id="note" cols="60" rows="2" value="%{project.note}"></s:textarea></td>
	</tr>
      <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">申请立项文档：</div></td>
      <td width="75%"></td>
      </tr>
      <%Project project = (Project)request.getAttribute("project"); 
       for(ProjectDocument doc:project.getProjectDocuments())//struts2 我实在不知道在这怎么用
         if(doc.getDocumentType()==DocumentType.申请立项文档)
         {%>
       <tr bgcolor="f5f5f5" id="<%=doc.getId()%>"> 
      <td width="25%"></td>
       <td width="75%"><%=doc.getDocName()%>(<%=doc.getSize()%>KB)&nbsp;&nbsp;&nbsp;<input type="button" class="frm_btn" value="删除" onClick="deleteItem(<%=doc.getId()%>)"/></td>
       </tr>
      <%}%>
      <tr bgcolor="f5f5f5"> 
     <td width="25%"> <div align="right"></div></td>
      <td width="75%"><input type="button" class="frm_btn" onclick="addApplyingComponent();" value="添加文件" /></td> 
     </tr>
      <tr bgcolor="f5f5f5" id="last" > 
      <td width="25%"></td>
      <td width="75%"><font color="#0099FF">-------------------------------------------------------------------------</font></td>
      </tr>
      <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">执行中文档：</div></td>
      <td width="75%"></td>
      </tr>
       <% for(ProjectDocument doc:project.getProjectDocuments())//我实在不知道在这怎么用struts2 标签，只能用最原始的方法，引入Java类弄
         if(doc.getDocumentType()==DocumentType.执行中文档)
         {%>
       <tr bgcolor="f5f5f5"  id="<%=doc.getId()%>" > 
      <td width="25%"></td>
      <td width="75%"><%=doc.getDocName()%>(<%=doc.getSize()%>KB)&nbsp;&nbsp;&nbsp;<input type="button" class="frm_btn" value="删除" onClick="deleteItem(<%=doc.getId()%>)"/></td>
      </tr>
      <%}%>
       <tr bgcolor="f5f5f5"> 
     <td width="25%"> <div align="right"></div></td>
      <td width="75%"><input type="button" class="frm_btn" onclick="addOngoingComponent();" value="添加文件" /></td> 
      </tr>
      <tr bgcolor="f5f5f5" id="ongoing"> 
      <td width="25%"></td>
      <td width="75%"><font color="#0099FF">-------------------------------------------------------------------------</font></td>
      </tr>
       <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right">结题文档：</div></td>
      <td width="75%"></td>
      </tr>
       <% for(ProjectDocument doc:project.getProjectDocuments())//struts2 我实在不知道在这怎么用
         if(doc.getDocumentType()==DocumentType.验收文档)
         {%>
       <tr id="<%=doc.getId()%>" bgcolor="f5f5f5"> 
      <td width="25%"></td>
      <td width="75%"><%=doc.getDocName()%>(<%=doc.getSize()%>KB)&nbsp;&nbsp;&nbsp;<input type="button" class="frm_btn" value="删除" onClick="deleteItem(<%=doc.getId()%>)"/></td> 
       </tr>
      <%}%>
       <tr bgcolor="f5f5f5"> 
      <td width="25%"> <div align="right"></div></td>
      <td width="75%"><input type="button" class="frm_btn" onclick="addFinishedComponent();" value="添加文件" /></td> 
      </tr>
      <tr bgcolor="f5f5f5" id="finished"> 
      <td width="25%"></td>
      <td width="75%"><font color="#0099FF">-------------------------------------------------------------------------</font></td>
      </tr>
    <tr bgcolor="f5f5f5"> 
      <td colspan="2"> <div align="center"> 
          <input type="submit" class="frm_btn" value=" 提 交 " onclick="return check();">
          &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="Button" value=" 返 回 " class="frm_btn" onclick="javascript:history.back()">
        </div></td>
    </tr>
  </table>
</s:form>
  </body>
</html>
